<?php

namespace app\api\model;

use think\facade\Db;
class ShopOrder extends Common
{
    public function __construct(array $data = [])
    {
        parent::__construct($data);
        //  用户基本账户表
        $this->table = 'shop_order';
    }
    /**
     * 获取数量
     * @param $searchWhere
     * @param $whereIn
     * @return float|string
     */
    public function getNumBystatus($searchWhere=[],$whereIn=[]){
        if(empty($whereIn)){
            return $this->checkNum($searchWhere);
        }else{
            $query = Db::name($this->table)->where($searchWhere);
            foreach($whereIn as $k=>$v) {
                $query->whereIn($k, $v);
            }
            return $query->count();
        }
    }

    /**
     * 获取订单列表
     * @param $searchWhere
     * @param $whereIn
     * @return float|int|string
     * @throws \think\db\exception\DbException
     */
    public function getInLists($searchWhere=[],$whereIn=[],$field='*',$group='',$order=[],$limit=[]){
        if(empty($whereIn)){
            return $this->getAllData($searchWhere,$field,$group,$order,$limit);
        }else{
            $query = Db::name($this->table)->where($searchWhere);
            foreach($whereIn as $k=>$v) {
                $query->whereIn($k, $v);
            }
            if(empty($limit) === FALSE) {
                $res = $query->order($order)->group($group)->limit($limit[0],$limit[1])->select();
            }else{
                $res = $query->order($order)->group($group)->select();
            }
            if(empty($res)){
                return [];
            }else{
                return $res->toArray();
            }
        }
    }
    public function getInfoBytime($searchWhere=[],$where,$condition,$field='*',$group='',$order=[]){
        return Db::name($this->table)->where($searchWhere)->whereBetweenTime('create_at',$condition,\Tools::getDateTimeByTime())->field($field)->find();
    }
}
